package com.webank.wedatasphere.qualitis.controller.thymeleaf;

import com.webank.wedatasphere.qualitis.project.dao.repository.ProjectMuLuRepository;
import com.webank.wedatasphere.qualitis.project.entity.ProjectMuLu;
import com.webank.wedatasphere.qualitis.response.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;

@Path("rest/biaozhun")
public class MuluRestMVC {


    @Autowired
    private ProjectMuLuRepository projectMuLuRepository;

    @POST
    @Path("deleteById")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Resp<?> muluDel(@RequestParam("id") long id) {
        projectMuLuRepository.deleteById(id);
        return Resp.Ok();
    }


    @POST
    @Path("muluUpdate")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Resp<?> muluUpdate(@RequestBody Map<String,Object> map) {
        String id = map.get("id").toString();
        ProjectMuLu one = projectMuLuRepository.getOne(Long.parseLong(id));
        one.setTitle(map.get("title").toString());
        projectMuLuRepository.save(one);
        return Resp.Ok();
    }


    @POST
    @Path("muluAdd")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Resp<?> muluAdd(@RequestBody ProjectMuLu projectMuLu) {
        projectMuLuRepository.save(projectMuLu);
        return Resp.Ok();
    }


}
